<template>
  <ve-line
    :legend-visible="false"
    :loading="loading"
    :data="chartData"
    :data-empty="dataEmpty"
    :settings="chartSettings"
    :colors="colors"
    :extend="extendsConfig"
    height="342px"
  />
</template>

<script>
import VeLine from 'v-charts/lib/line.common';
export default {
  components: {
    VeLine
  },
  data() {
    return {
      loading: true,
      dataEmpty: false,
      chartSettings: {
        labelMap: {
          date: '日期',
          user_count: '付费人数'
        },
        yAxisName: ['付费人数'],
        yAxisType: ['KMB']
      },
      extendsConfig: {
        series: {
          smooth: false
        },
        xAxis(v) {
          v.forEach(i => {
            i.boundaryGap = false;
            i.axisLabel = {
              showMaxLabel: true,
              rotate: 45
            };
          });

          return v;
        },
        yAxis(v) {
          v.forEach(i => {
            i.minInterval = 1;
          });

          return v;
        }
      },
      colors: ['#F54030'],
      chartData: {
        columns: ['date', 'user_count'],
        rows: []
      }
    };
  },
  created() {
    this.loadData();
  },
  methods: {
    loadData: function() {
      this.$http.get(
        '/admin/data/survey/today/payment/usercount',
        {
          time: 'today'
        },
        response => {
          const data = response.data.rows;
          if (data.length == 0) {
            this.dataEmpty = true;
            this.chartData.rows = [];
          } else {
            this.dataEmpty = false;
            this.chartData.rows = data;
          }

          this.loading = false;
        },
        _ => {
          this.loading = false;
        },
        false
      );
    }
  }
};
</script>

<style></style>
